﻿using MatlabWork.Dal;
using MatlabWork.Entity;
using OfficeOpenXml;
using Prism.DryIoc;
using Prism.Ioc;
using System.Configuration;
using System.Data;
using System.IO;
using System.Net.Http.Headers;
using System.Windows;
using TestingPlatForm.MissionContrl.Dal;
using TestingPlatForm.MissionContrl.Entity;
using TestingPlatForm.MissionContrl.ViewModels;
using TestingPlatForm.MissionContrl.Views;

namespace TestingPlatForm.MissionContrl
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<MainWindow, MainWindowViewModel>();
            containerRegistry.RegisterForNavigation<IndexView>();
            containerRegistry.RegisterForNavigation<SettingsView>();
            containerRegistry.RegisterForNavigation<CalculatorView>();
            containerRegistry.RegisterForNavigation<MemoView>();
            containerRegistry.RegisterForNavigation<RAHView>();
            containerRegistry.RegisterForNavigation<ConnectWayView>();
            Initial();
            InitialLink();
            InitialVal.InitialDic();
            InitialVal.RefreshValue();
            InitialVal.InitialList();
        }

        protected override void InitializeShell(Window shell)
        {
            base.InitializeShell(shell);
        }

        private void Initial()
        {
            configData configData = new configData();
            string currentDirectory = Directory.GetCurrentDirectory();
            string logConfigFile = currentDirectory + "\\config\\BsSetting.config";
            if (File.Exists(logConfigFile))
            {
                string[] readText = File.ReadAllLines(logConfigFile);
                for (int nIndex = 0; nIndex < readText.Length; nIndex++)
                {
                    string line = readText[nIndex];
                    if (line.Contains("fu="))
                    {
                        // 用户链路KU
                        configData.fu = double.Parse(readText[nIndex].Replace("fu=", ""));
                    }
                    if (line.Contains("fu_up="))
                    {
                        // 用户链路KU
                        configData.fu_up = double.Parse(readText[nIndex].Replace("fu_up=", ""));
                    }
                    if (line.Contains("fu_down="))
                    {
                        // 用户链路KU
                        configData.fu_down = double.Parse(readText[nIndex].Replace("fu_down=", ""));
                    }
                    if (line.Contains("fu_up_ot="))
                    {
                        // 用户链路KU
                        configData.fu_up_ot = double.Parse(readText[nIndex].Replace("fu_up_ot=", ""));
                    }
                    if (line.Contains("fu_down_ot="))
                    {
                        // 用户链路KU
                        configData.fu_down_ot = double.Parse(readText[nIndex].Replace("fu_down_ot=", ""));
                    }
                    if (line.Contains("ff="))
                    {
                        // 馈电链路QV
                        configData.ff = double.Parse(readText[nIndex].Replace("ff=", ""));
                    }
                    if (line.Contains("ff_up="))
                    {
                        // 馈电链路QV
                        configData.ff_up = double.Parse(readText[nIndex].Replace("ff_up=", ""));
                    }
                    if (line.Contains("ff_down="))
                    {
                        // 馈电链路QV
                        configData.ff_down = double.Parse(readText[nIndex].Replace("ff_down=", ""));
                    }
                    if (line.Contains("ff_up_ot="))
                    {
                        // 馈电链路QV
                        configData.ff_up_ot = double.Parse(readText[nIndex].Replace("ff_up_ot=", ""));
                    }
                    if (line.Contains("ff_down_ot="))
                    {
                        // 馈电链路QV
                        configData.ff_down_ot = double.Parse(readText[nIndex].Replace("ff_down_ot=", ""));
                    }
                    if (line.Contains("ff_sway"))
                    {
                        // 馈电链路QV
                        configData.ff_sway = double.Parse(readText[nIndex].Replace("ff_sway=", ""));
                    }
                    if (line.Contains("st="))
                    {
                        // 终端
                       configData.st = readText[nIndex].Replace("st=", "");
                    }
                   
                    if (line.Contains("x_st1="))
                    {
                        // 终端X2
                        configData.x_st1 = double.Parse(readText[nIndex].Replace("x_st1=", "").ToString());
                    }
                    if (line.Contains("y_st1="))
                    {
                        // 终端Y2a
                        configData.y_st1 = double.Parse(readText[nIndex].Replace("y_st1=", "").ToString());
                    }

                    if (line.Contains("z_st1="))
                    {
                        configData.z_st1 = double.Parse(readText[nIndex].Replace("z_st1=","").ToString());
                    }

                    if (line.Contains("x_st2="))
                    {
                        // 终端X2
                        configData.x_st2 = double.Parse(readText[nIndex].Replace("x_st2=", "").ToString());
                    }
                    if (line.Contains("y_st2="))
                    {
                        // 终端Y2a
                        configData.y_st2 = double.Parse(readText[nIndex].Replace("y_st2=", "").ToString());
                    }

                    if (line.Contains("z_st2="))
                    {
                        configData.z_st2 = double.Parse(readText[nIndex].Replace("z_st2=", "").ToString());
                    }

                    if (line.Contains("x_bs="))
                    {
                        // 基站X
                        configData.x_bs = double.Parse(readText[nIndex].Replace("x_bs=", "").ToString());
                    }

                    if (line.Contains("y_bs="))
                    {
                        // 基站X
                        configData.y_bs = double.Parse(readText[nIndex].Replace("y_bs=", "").ToString());
                    }

                    if (line.Contains("z_bs="))
                    {
                        // 基站X
                        configData.z_bs = double.Parse(readText[nIndex].Replace("z_bs=", "").ToString());
                    }

                    if (line.Contains("fileName="))
                    {
                        // 基站X
                        configData.fileName = readText[nIndex].Replace("fileName=", "");
                    }

                    if (line.Contains("OPS_IP="))
                    {
                        configData.OPS_IP = readText[nIndex].Replace("OPS_IP=", "").ToString();
                    }
                }

            }
            GlobalEntity.configData = configData;
        }

        private void InitialLink()
        {
            LinkData linkData = new LinkData();
            string currentDirectory = Directory.GetCurrentDirectory();
            string logConfigFile = currentDirectory + "\\config\\LinkSetting.config";
            if (File.Exists(logConfigFile))
            {
                string[] readText = File.ReadAllLines(logConfigFile);
                for (int nIndex = 0; nIndex < readText.Length; nIndex++)
                {
                    string line = readText[nIndex];
                    if (line.Contains("UPLinkWay="))
                    {
                        // 用户链路KU
                        linkData.LinkWay = double.Parse(readText[nIndex].Replace("UPLinkWay=", ""));
                    }
                    if (line.Contains("upLinkPower="))
                    {
                        // 用户链路KU
                        linkData.upLinkPower = double.Parse(readText[nIndex].Replace("upLinkPower=", ""));
                    }
                    if (line.Contains("Lattenuation="))
                    {
                        // 用户链路KU
                        linkData.Lattenuation = double.Parse(readText[nIndex].Replace("Lattenuation=", ""));
                    }
                    if (line.Contains("receptionLoss="))
                    {
                        // 用户链路KU
                        linkData.receptionLoss = double.Parse(readText[nIndex].Replace("receptionLoss=", ""));
                    }
                    if (line.Contains("LXGain="))
                    {
                        // 用户链路KU
                        linkData.LXgain = double.Parse(readText[nIndex].Replace("LXGain=", ""));
                    }
                    if (line.Contains("XVattenuation="))
                    {
                        // 用户链路KU
                        linkData.XVattenuation = double.Parse(readText[nIndex].Replace("XVattenuation=", ""));
                    }
                    if (line.Contains("SendGain="))
                    {
                        // 用户链路KU
                        linkData.SendGain = double.Parse(readText[nIndex].Replace("SendGain=", ""));
                    }
                    if (line.Contains("receiveGain="))
                    {
                        // 用户链路KU
                        linkData.receiveGain = double.Parse(readText[nIndex].Replace("receiveGain=", ""));
                    }
                    if (line.Contains("IFpower="))
                    {
                        // 用户链路KU
                        linkData.IFpower = double.Parse(readText[nIndex].Replace("IFpower=", ""));
                    }
                    if (line.Contains("downLinkWay="))
                    {
                        // 用户链路KU
                        linkData.downLinkWay = double.Parse(readText[nIndex].Replace("downLinkWay=", ""));
                    }
                    if (line.Contains("Xattenuation="))
                    {
                        // 馈电链路QV
                        linkData.Xattenuation = double.Parse(readText[nIndex].Replace("Xattenuation=", ""));
                    }
                    if (line.Contains("gain="))
                    {
                        // 馈电链路QV
                        linkData.gain = double.Parse(readText[nIndex].Replace("gain=", ""));
                    }
                    if (line.Contains("transmissionGain="))
                    {
                        // 馈电链路QV
                        linkData.transmissionGain = double.Parse(readText[nIndex].Replace("transmissionGain=", ""));
                    }
                    if (line.Contains("receptionGain="))
                    {
                        // 馈电链路QV
                        linkData.receptionGain = double.Parse(readText[nIndex].Replace("receptionGain=", ""));
                    }
                    if (line.Contains("conversionLoss="))
                    {
                        // 终端
                       linkData.conversionLoss = double.Parse( readText[nIndex].Replace("conversionLoss=", ""));
                    }

                    if (line.Contains("inputPower="))
                    {
                        // 终端X2
                        linkData.inputPower = double.Parse(readText[nIndex].Replace("inputPower=", ""));
                    }
                    if (line.Contains("cableLoss="))
                    {
                        // 终端Y2a
                       linkData.cableLoss = double.Parse(readText[nIndex].Replace("cableLoss=", "").ToString());
                    }

                   
                }

            }
            GlobalEntity.LinkData = linkData;
        }

    }

}
